# When working with color values it can sometimes be useful to extract the individual red, green, and blue (RGB) component values for a color. Implement a function that meets these requirements:
# Accepts a case-insensitive hexadecimal color string as its parameter (ex. "#FF9933" or "#ff9933")
# Returns a Map<String, int> with the structure {r: 255, g: 153, b: 51} where r, g, and b range from 0 through 255


#先不用正则表达式实现
def hex_string_to_RGB(hex_string):
    # your code here
    target_map = {}
    target_map['r'] = int('0x'+hex_string[1:3],base=16)
    target_map['g'] = int('0x' + hex_string[3:5], base=16)
    target_map['b'] = int('0x' + hex_string[5:7], base=16)
    return target_map


import re
#使用正则表达式
def hex_string_to_RGB1(hex_string):
    regex = r"(\w{2})(\w{2})(\w{2})"
    m = re.search(regex, hex_string)#match函数从头开始匹配，search可以从中间开始匹配
    target_map = {}
    target_map['r'] = int('0x'+m.group(1),base=16)
    target_map['g'] = int('0x' + m.group(2), base=16)
    target_map['b'] = int('0x' + m.group(3), base=16)
    return target_map

print(hex_string_to_RGB1("#FF9933"))